package cn.itcast.mapper;

import cn.itcast.domain.User;
import org.apache.ibatis.annotations.*;

import java.util.List;

public interface UserMapper {
    //查询所有用户
    @Select("select * from user")
    List<User>  findAll();

    //增加一个用户
    @Insert("insert into user(id,username,address) values (id,#{username},#{address})")
    void insert(User user);

    //删除一条用户信息
    @Delete("delete from user where id = #{uid}")
    void delete(int id);

    //修改一条用户信息
     @Update("update user set username= #{username} where id = #{id}")
    void update(User user);

     //查询用户名和密码
    @Select("select * from user where username = #{username} and password=#{password}")
    //@ResultMap("userMap")
    /*@Results属性:id 唯一标识,可以供其xml配置使用:及resultMap = "userMap"*/
    @Results(id = "userMap",value = {
            /*@Result的id属性是为了声明是主键列*/
            @Result(id = true,column = "id",property = "id"),
            @Result(column = "username",property = "username"),
            @Result(column = "password",property = "password")
    })
    User findUsernameAndPwd( @Param("username") String username, @Param("password") String password);

    List<User> findUser();
}
